home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK2.toast / Development Kits (Disc 2) / ScriptX / Documentation / Code Examples from Docs / compguid / controlr / bouncing.sx
Encoding:
Text File  |  1996-05-21  |  1.5 KB  |  62 lines  |  [TEXT/ttxt]

  1. -- <<<
  2. -- Filename: BOUNCING.SX
  3.  
  4. -- Purpose: Demonstrates how to make an object controlled by gravity in a space.
  5.  
  6. -- Other Files Required:  (none)
  7.  
  8. -- Instructions to User: You should see a black ball bouncing around in a window.
  9. --    To start the ball bouncing again, type "restart myBall"
  10.  
  11. -- Specialized Classes: Ball
  12.  
  13. ------------------------------------------------------------------------
  14.  
  15. -- Make a projectile by defining a class that 
  16. -- inherits from both TwoShape and Projectile 
  17. class Ball (TwoDShape, Projectile) 
  18. end 
  19.  
  20. -- Create an instance of Ball and initialize it 
  21. method init self {class Ball} #rest args -> 
  22. (
  23.     apply nextMethod self args
  24.     self.x := 50 
  25.     self.y := 50 
  26.     self.elasticity := 1 
  27.     self.velocity := new Point x:-8.0 y:4.0
  28. )
  29.  
  30. -- Method to restart the ball bouncing 
  31. method restart self {class Ball} -> 
  32. (
  33.     self.x := 50 
  34.     self.y := 50 
  35.     self.velocity := new Point x:-8.0 y:4.0
  36. )
  37.  
  38. -- Set up the window 
  39. global myWindow := new Window boundary:(new Rect x2:400 y2:250) fill:blackBrush
  40.     myWindow.x := 40
  41.     myWindow.y := 40
  42.     show myWindow
  43.  
  44. -- Create the controllers
  45. global myGravity := new Gravity space:myWindow 
  46. myGravity.wholeSpace := true
  47.  
  48. global myBounce := new Bounce space:myWindow 
  49. myBounce.wholeSpace := true
  50.  
  51. global myMovement := new Movement space:myWindow 
  52. myMovement.wholeSpace := true
  53.  
  54. -- Create an instance of Ball and append it to the space
  55. global myBall := new Ball target:(new Oval x2:20 y2:20)  fill:whiteBrush 
  56. prepend myWindow myBall
  57.  
  58.  
  59. -- To start the ball bouncing again, type "restart myBall"
  60.  
  61.  
  62.